﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.SQLite;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Schedule
{
    public partial class ScheduleForm : Form
    {
        private static string connStr = Properties.Settings.Default.ConnectionString;
        private DataTableManage CourseDataTableManage = new DataTableManage(new DataTable("subject")) ;
        private CourseDataManage courseDataManage = new CourseDataManage();
        private DDLManage DeadlineManage = new DDLManage();
        public static bool ifColor = true;

        public ScheduleForm()
        {
            InitializeComponent();
            courseDataManage.dataInit();//初始化数据库
            CourseDataTableManage.dataTableInit();//初始化课程表
            CourseDataTableManage.dataTableFill();
            
            this.dataGridView1.DataSource = CourseDataTableManage.CourseDataTable;//绑定课程表数据
            DeadlineManage.dataInit(dataGridView1);//初始化ddl数据
            
        }

        private void addCourseBtn_Click(object sender, EventArgs e)
        {
            AddCourseForm addCourseForm = new AddCourseForm();
            addCourseForm.Show();
            addCourseForm.SubmitClick += CourseDataTableManage.dataTableFill;
        }

        private void button1_Click(object sender, EventArgs e)
        {//删除课程

            courseDataManage.deleteCourse(dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex + 1);
            CourseDataTableManage.dataTableFill();//更新课程表
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {

            courseDataManage.getCourseInfo(e.ColumnIndex, e.RowIndex + 1,out string courseID,out string courseName);
            if (courseID == "")
                MessageBox.Show("无课程");
            else
            new CheckInfoForm(courseID,courseName).Show();


        }

        private void button2_Click(object sender, EventArgs e)
        {
            AddDeadlineForm addDeadlineForm = new AddDeadlineForm(dataGridView1.CurrentCell.ColumnIndex, dataGridView1.CurrentCell.RowIndex + 1);
            addDeadlineForm.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (ifColor)
            {
                ifColor = false;
                button3.Text = "开启提醒";
            }
            else
            {
                ifColor = true;
                button3.Text = "关闭提醒";
            }
            DeadlineManage.fillColor();
        }
    }
}
